import axios from 'axios';
// import { message } from 'ant-design-vue';

const axiosInstance = axios.create({
  timeout: 60 * 1000,
  baseURL: '/'
});

axiosInstance.interceptors.request.use(
  config => {
    config.headers.Authorization = 'xci0higo6skSRqG3TLBziNAM1X9Te7U+RU1Iv99xo1YxV22UvQCa+9WxsMQtjNjn9f6JuldPjQfvFduJ3i3u66SVlqtljTA0nzxlxiogEcVj/DEfusqgWsa8DyQftTwo4Z+2KhMd8mL7xM7Li9DmVH/CfBsaFGjLGpQmKev4V+XERsYG7fBwgzKvCm1N0kYAxAvGs9vtqQ8ToVXJZW21ZQ==';
    config.headers.apiToken = 'xci0higo6skSRqG3TLBziNAM1X9Te7U+RU1Iv99xo1YxV22UvQCa+9WxsMQtjNjn9f6JuldPjQfvFduJ3i3u66SVlqtljTA0nzxlxiogEcVj/DEfusqgWsa8DyQftTwo4Z+2KhMd8mL7xM7Li9DmVH/CfBsaFGjLGpQmKev4V+XERsYG7fBwgzKvCm1N0kYAxAvGs9vtqQ8ToVXJZW21ZQ==';
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

axiosInstance.interceptors.response.use(
  response => {
    const { code, msg } = response.data;

    if (code === '0') {
      return response.data;
    } else if (code === '-1') {
      console.log('response code -1', msg);
      // message.error(msg);
      return Promise.reject(response.data);
    }
    return Promise.reject(response.data);
  },
  error => {
    return Promise.reject(error);
  }
);

export default axiosInstance;
